﻿using JX.Core.Entity;
using JX.Infrastructure;
using JX.Infrastructure.Framework;
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace JX.Application
{
	public partial interface IUsersServiceAppDapper : IServiceAppDapper<UsersEntity>
	{
		#region 得到实体
		/// <summary>
		/// 通过会员名得到会员实体类
		/// </summary>
		/// <param name="userName"></param>
		/// <returns></returns>
		UsersEntity GetByUserName(string userName);
		#endregion

		#region 登录、退出、修改密码
		/// <summary>
		/// 会员登录
		/// </summary>
		/// <param name="userName"></param>
		/// <param name="password"></param>
		/// <returns></returns>
		Task<IdentityResult> Login(string userName, string password);
		/// <summary>
		/// 会员退出
		/// </summary>
		/// <param name="claimsPrincipal"></param>
		/// <returns></returns>
		bool Logout(ClaimsPrincipal claimsPrincipal);
		/// <summary>
		/// 修改密码
		/// </summary>
		/// <param name="userID"></param>
		/// <param name="oldPwd"></param>
		/// <param name="newPwd"></param>
		/// <returns></returns>
		Task<ResultInfo> ModifyPassword(int userID, string oldPwd, string newPwd);
		#endregion

		#region 得到会员状态
		/// <summary>
		/// 得到会员状态
		/// </summary>
		/// <param name="userID">会员ID</param>
		/// <returns></returns>
		UserStatusEnum GetUserStatus(int userID);
		/// <summary>
		/// 得到会员状态
		/// </summary>
		/// <param name="userName">会员名称</param>
		/// <returns></returns>
		UserStatusEnum GetUserStatus(string userName);
		#endregion

		#region 添加会员
		/// <summary>
		/// 添加会员、联系人、联系人扩展。
		/// 1、添加会员。
		/// 2、添加联系人，存在相同会员名的联系人则修改。
		/// 3、添加联系人扩展，存在相同会员名的联系人扩展则修改。
		/// </summary>
		/// <param name="usersInfo"></param>
		/// <param name="contacterInfo"></param>
		/// <returns></returns>
		bool AddUserFull(UsersEntity usersInfo, ContacterEntity contacterInfo);
		/// <summary>
		/// 添加会员、联系人、联系人扩展。
		/// 1、添加会员。
		/// 2、添加联系人，存在相同会员名的联系人则修改。
		/// 3、添加联系人扩展，存在相同会员名的联系人扩展则修改。
		/// </summary>
		/// <param name="usersInfo"></param>
		/// <param name="contacterInfo"></param>
		/// <returns></returns>
		Task<bool> AddUserFullAsync(UsersEntity usersInfo, ContacterEntity contacterInfo);
		#endregion

		#region 删除用户及相关权限
		/// <summary>
		/// 删除用户及相关权限
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		bool DelUserFull(int id);
		/// <summary>
		/// 删除用户及相关权限
		/// </summary>
		/// <param name="userName"></param>
		/// <returns></returns>
		bool DelUserFull(string userName);
		/// <summary>
		/// 批量删除用户及相关权限
		/// </summary>
		/// <param name="ids"></param>
		bool BatchDel(string ids);
		/// <summary>
		/// 删除用户相关信息。
		/// 1、字段权限（FieldPermissions）。
		/// 2、节点权限（NodePermissions）。
		/// 3、专题权限（SpecialPermissions）。
		/// 4、会员有效期兑换日志（UserValidLog）。
		/// 5、会员点券兑换日志（UserPointLog）。
		/// 6、会员积分兑换日志（UserExpLog）。
		/// 7、联系人相关信息（Contacter、U_UserText、ClientLog、RemindItem）。
		/// 8、收藏夹信息。
		/// 9、会员添加的好友信息和被别人添加为好友的信息。
		/// </summary>
		/// <param name="id"></param>
		/// <param name="userName"></param>
		void DeleteUserRelation(int id, string userName);
		#endregion

		#region 修改会员
		/// <summary>
		/// 修改会员、联系人、联系人扩展。
		/// 1、修改会员。
		/// 2、修改联系人。
		/// 3、修改联系人扩展。
		/// </summary>
		/// <param name="usersInfo"></param>
		/// <param name="contacterInfo"></param>
		/// <returns></returns>
		bool UpdateUserFull(UsersEntity usersInfo, ContacterEntity contacterInfo);
		/// <summary>
		/// 修改会员、联系人、联系人扩展。
		/// 1、修改会员。
		/// 2、修改联系人。
		/// 3、修改联系人扩展。
		/// </summary>
		/// <param name="usersInfo"></param>
		/// <param name="contacterInfo"></param>
		/// <returns></returns>
		Task<bool> UpdateUserFullAsync(UsersEntity usersInfo, ContacterEntity contacterInfo);
		#endregion

		#region 会员升级为企业会员
		/// <summary>
		/// 会员升级为企业会员
		/// </summary>
		/// <param name="companyId"></param>
		/// <param name="userId"></param>
		/// <param name="userType"></param>
		/// <param name="companyClientId"></param>
		/// <returns></returns>
		bool UpdateForCompany(int companyId, int userId, int userType, int companyClientId);
		/// <summary>
		/// 会员升级为企业会员
		/// </summary>
		/// <param name="companyId"></param>
		/// <param name="userId"></param>
		/// <param name="userType"></param>
		/// <param name="companyClientId"></param>
		/// <returns></returns>
		Task<bool> UpdateForCompanyAsync(int companyId, int userId, int userType, int companyClientId);
		#endregion

		#region 会员激励
		/// <summary>
		/// 会员激励
		/// </summary>
		/// <param name="eType">激励类型：0：资金；1：积分；2：点券；3：有效期；</param>
		/// <param name="eAction">激励方向：Add：增加；Minus：减少；</param>
		/// <param name="idType">ID类型：0：所有会员；1：会员ID；2：会员名；3：会员组；</param>
		/// <param name="ids">会员ID或会员名或会员组ID</param>
		/// <param name="howMany">激励数量</param>
		/// <param name="remark">备注</param>
		/// <param name="memo">内部记录</param>
		/// <returns></returns>
		bool UserEncourageStrategy(int eType,string eAction, int idType, string ids, int howMany, string remark="", string memo="");
		/// <summary>
		/// 会员激励
		/// </summary>
		/// <param name="eType">激励类型：0：资金；1：积分；2：点券；3：有效期；</param>
		/// <param name="eAction">激励方向：Add：增加；Minus：减少；</param>
		/// <param name="idType">ID类型：0：所有会员；1：会员ID；2：会员名；3：会员组；</param>
		/// <param name="ids">会员ID或会员名或会员组ID</param>
		/// <param name="howMany">激励数量</param>
		/// <param name="remark">备注</param>
		/// <param name="memo">内部记录</param>
		/// <returns></returns>
		Task<bool> UserEncourageStrategyAsync(int eType, string eAction, int idType, string ids, int howMany, string remark = "", string memo = "");

		/// <summary>
		/// 会员激励
		/// </summary>
		/// <param name="eType">激励类型：0：资金；1：积分；2：点券；3：有效期；</param>
		/// <param name="eAction">激励方向：Add：增加；Minus：减少；</param>
		/// <param name="idType">ID类型：0：所有会员；1：会员ID；2：会员名；3：会员组；</param>
		/// <param name="ids">会员ID或会员名或会员组ID</param>
		/// <param name="howMany">激励数量</param>
		/// <param name="remark">备注</param>
		/// <param name="memo">内部记录</param>
		/// <returns></returns>
		bool UserEncourageStrategy(int eType, string eAction, int idType, string ids, decimal howMany, string remark = "", string memo = "");
		/// <summary>
		/// 会员激励
		/// </summary>
		/// <param name="eType">激励类型：0：资金；1：积分；2：点券；3：有效期；</param>
		/// <param name="eAction">激励方向：Add：增加；Minus：减少；</param>
		/// <param name="idType">ID类型：0：所有会员；1：会员ID；2：会员名；3：会员组；</param>
		/// <param name="ids">会员ID或会员名或会员组ID</param>
		/// <param name="howMany">激励数量</param>
		/// <param name="remark">备注</param>
		/// <param name="memo">内部记录</param>
		/// <returns></returns>
		Task<bool> UserEncourageStrategyAsync(int eType, string eAction, int idType, string ids, decimal howMany, string remark = "", string memo = "");
		#endregion

		#region 商户成员管理
		/// <summary>
		/// 从商户中移除
		/// </summary>
		/// <param name="UserName"></param>
		/// <returns></returns>
		bool RemoveFromCompany(string UserName);
		/// <summary>
		/// 从商户中移除
		/// </summary>
		/// <param name="UserName"></param>
		/// <returns></returns>
		Task<bool> RemoveFromCompanyAsync(string UserName);

		/// <summary>
		/// 升级为商户管理员
		/// </summary>
		/// <param name="UserName"></param>
		/// <returns></returns>
		bool AddToCompanyAdmin(string UserName);
		/// <summary>
		/// 升级为商户管理员
		/// </summary>
		/// <param name="UserName"></param>
		/// <returns></returns>
		Task<bool> AddToCompanyAdminAsync(string UserName);

		/// <summary>
		/// 降级为商户的普通成员
		/// </summary>
		/// <param name="UserName"></param>
		/// <returns></returns>
		bool RemoveFromCompanyAdmin(string UserName);
		/// <summary>
		/// 降级为商户的普通成员
		/// </summary>
		/// <param name="UserName"></param>
		/// <returns></returns>
		Task<bool> RemoveFromCompanyAdminAsync(string UserName);

		/// <summary>
		/// 允许待审核用户成为商户的正式成员
		/// </summary>
		/// <param name="UserName"></param>
		/// <param name="companyClientId"></param>
		/// <returns></returns>
		bool AgreeJoinCompany(string UserName, int companyClientId);
		/// <summary>
		/// 允许待审核用户成为商户的正式成员
		/// </summary>
		/// <param name="UserName"></param>
		/// <param name="companyClientId"></param>
		/// <returns></returns>
		Task<bool> AgreeJoinCompanyAsync(string UserName, int companyClientId);
		#endregion

		/// <summary>
		/// 通过实体类生成会员对应的ClaimsPrincipal对像
		/// </summary>
		/// <param name="entity"></param>
		/// <returns></returns>
		ClaimsPrincipal CreateClaimsIdentity(UsersEntity entity);
	}
}
